package com.itheima.controller;


import com.itheima.common.CommonResult;
import com.itheima.common.PageInfo;
import com.itheima.dto.OrderUpdateDto;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    //订单分页查询
    @GetMapping("/page")   //name判断了为空的情况，其他为空情况没判断，因此设置一个默认值@RequestParam
    public CommonResult page(String number ,String beginTime,String endTime,
                             //默认page为1
                             @RequestParam(defaultValue = "1") Integer page ,
                             //默认pageSize为10
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Order> page1 = orderService.page(number,beginTime,endTime,page, pageSize);
        return CommonResult.success(page1);
    }

    //修改订单状态
    @PutMapping
    public CommonResult updateOrder(@RequestBody OrderUpdateDto orderUpdateDto){
        boolean res = orderService.updateOrder(orderUpdateDto);
        if (!res){
            return CommonResult.error("修改订单状态失败");
        }
        return CommonResult.success("修改订单状态成功");
    }

}
